package com.easyctba.core.controller;

import java.util.List;

import com.easyctba.core.domain.bo.*;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.easyctba.common.idempotent.annotation.RepeatSubmit;
import com.easyctba.common.log.annotation.Log;
import com.easyctba.common.web.core.BaseController;
import com.easyctba.common.mybatis.core.page.PageQuery;
import com.easyctba.common.core.domain.R;
import com.easyctba.common.core.validate.AddGroup;
import com.easyctba.common.core.validate.EditGroup;
import com.easyctba.common.log.enums.BusinessType;
import com.easyctba.common.excel.utils.ExcelUtil;
import com.easyctba.core.domain.vo.CtbaFiasVo;
import com.easyctba.core.service.ICtbaFiasService;
import com.easyctba.common.mybatis.core.page.TableDataInfo;

/**
 * 弗兰德斯分析
 * 前端访问路由地址为:/core/fias
 *
 * @author Huang
 * @date 2024-03-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fias")
public class CtbaFiasController extends BaseController {

    private final ICtbaFiasService ctbaFiasService;

    /**
     * 查询弗兰德斯分析列表
     */
    @SaCheckPermission("core:fias:list")
    @GetMapping("/list")
    public TableDataInfo<CtbaFiasVo> list(CtbaFiasBo bo, PageQuery pageQuery) {
        return ctbaFiasService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出弗兰德斯分析列表
     */
    @SaCheckPermission("core:fias:export")
    @Log(title = "弗兰德斯分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CtbaFiasBo bo, HttpServletResponse response) {
        List<CtbaFiasVo> list = ctbaFiasService.queryList(bo);
        ExcelUtil.exportExcel(list, "弗兰德斯分析", CtbaFiasVo.class, response);
    }

    /**
     * 获取弗兰德斯分析详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("core:fias:query")
    @GetMapping("/{id}")
    public R<CtbaFiasVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(ctbaFiasService.queryById(id));
    }

    /**
     * 新增弗兰德斯分析
     */
    @SaCheckPermission("core:fias:add")
    @Log(title = "弗兰德斯分析", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CtbaFiasBo bo) {
        return toAjax(ctbaFiasService.insertByBo(bo));
    }

    /**
     * 修改弗兰德斯分析
     */
    @SaCheckPermission("core:fias:edit")
    @Log(title = "弗兰德斯分析", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CtbaFiasBo bo) {
        return toAjax(ctbaFiasService.updateByBo(bo));
    }

    /**
     * 删除弗兰德斯分析
     *
     * @param ids 主键串
     */
    @SaCheckPermission("core:fias:remove")
    @Log(title = "弗兰德斯分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(ctbaFiasService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 根据项目id获取fias分析信息
     * @param id 项目id
     * @return VO对象
     */
    @GetMapping("/v1/{id}")
    public R<CtbaFiasVo> getInfoByUserAndProject(@NotNull(message = "项目id不能为空") @PathVariable Long id) {
        return ctbaFiasService.getInfoByUserAndProject(id);
    }
    /**
     * 初始化FIAS分析，设置编码间隔和编码视频的起止时间，并修改状态以进入下一步
     */
    @PostMapping("/fiasConfig")
    public R<Void> initSt(@Validated(EditGroup.class) @RequestBody FiasConfigBo bo){
        return ctbaFiasService.fiasConfig(bo);
    }

    /**
     * 上一步，返回上传视频页面
     * @param id FIAS分析id
     */
    @PutMapping("/preUpload/{id}")
    public R<Void> pre(@NotNull(message = "主键不能为空") @PathVariable Long id){
        return ctbaFiasService.preUpload(id);
    }

    /**
     * 下一步，前往编码页面
     * @param id fias分析id
     */
    @PutMapping("/nextToEncode/{id}")
    public R<Void> nextToEncode(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return ctbaFiasService.nextToEncode(id);
    }

    /**
     * 编码fias
     */
    @PostMapping("/encode/{id}")
    public R<Void> encode(@Validated(EditGroup.class) @RequestBody FiasEncodeBo bo, @PathVariable Long id){
        return ctbaFiasService.encode(bo,id);
    }

    /**
     * 添加折线
     * @return
     */
    @PostMapping("/front/polyline")
    public R addPolyline(@RequestBody FiasAddPolylineBo bo){
        return ctbaFiasService.addPolyline(bo);
    }

    /**
     * 获取折线
     * @param id fias id
     */
    @GetMapping("/front/polyline/{id}")
    public R getPolyline(@NotNull(message = "主键不能为空") @PathVariable Long id){
        return ctbaFiasService.getPolyline(id);
    }

    /**
     * 下一步，前往下载页面
     * @param id fias分析id
     */
    @PutMapping("/nextToDownload/{id}")
    public R<Void> nextToDownload(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return ctbaFiasService.nextToDownload(id);
    }

    /**
     * 上一步，前往折线分析页面
     * @param id fias分析id
     */
    @PutMapping("/preToPolyline/{id}")
    public R<Void> preToPolyline(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return ctbaFiasService.preToPolyline(id);
    }

    /**
     * 获取雷达图
     * @param id fias id
     */
    @GetMapping("/front/radar/{id}")
    public R radar(@NotNull(message = "主键不能为空") @PathVariable Long id){
        return ctbaFiasService.getRadar(id);
    }

    @GetMapping("/front/result/{id}")
    public R result(@NotNull(message = "主键不能为空") @PathVariable Long id){
        return ctbaFiasService.result(id);
    }
}
